package com.fancy.learncenter.ui.fragment;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.BaseBean;
import com.fancy.learncenter.bean.CartoonAnswerKeysBean;
import com.fancy.learncenter.bean.CartoonAnswersBean;
import com.fancy.learncenter.bean.CartoonCommitAnswerBean;
import com.fancy.learncenter.bean.CartoonGetAnswerResultBean;
import com.fancy.learncenter.bean.CartoonGetHomeAnswerBean;
import com.fancy.learncenter.bean.CartoonMediaBean;
import com.fancy.learncenter.bean.CartoonOptionsBean;
import com.fancy.learncenter.bean.CartoonStemsBean;
import com.fancy.learncenter.bean.CartoonTextsBean;
import com.fancy.learncenter.bean.CheckDoQuestion;
import com.fancy.learncenter.bean.QuestionVOsBean;
import com.fancy.learncenter.common.JumpIntentKey;
import com.fancy.learncenter.common.MyApplication;
import com.fancy.learncenter.net.CustomNetCallBack;
import com.fancy.learncenter.net.CustomNetSubscriber;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.ui.activity.CartoonWorkQuestionTypeActivity;
import com.fancy.learncenter.ui.activity.CatoonExpandActivity;
import com.fancy.learncenter.ui.adapter.GridViewAdapter;
import com.fancy.learncenter.ui.view.CartoonAnalysisPopu;
import com.fancy.learncenter.ui.view.DragGridView;
import com.fancy.learncenter.utils.CartoonToastUtils;
import com.fancy.learncenter.utils.LogUtil;
import com.fancy.learncenter.utils.NetUtil;
import com.fancy.learncenter.utils.ProgressUtil;
import com.fancy.learncenter.utils.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.ResponseBody;
import retrofit2.Response;

import static com.fancy.learncenter.common.JumpIntentKey.CARTOON_BUTTON_STATUS.STATUS_ANALYSIS;

/**
 * 看单词拼图
 */
public class SeeWordPuzzleNewFragment extends MyBaseFragment implements View.OnClickListener {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @Bind(R.id.commit_image)
    ImageView commitImage;
    @Bind(R.id.question_name)
    TextView questionName;
    boolean isAniming = false;
    @Bind(R.id.drag_grid_view)
    DragGridView dragGridView;
    @Bind(R.id.previous_question)
    ImageView previousQuestion;
    @Bind(R.id.next_question)
    ImageView nextQuestion;
    @Bind(R.id.bottom_layout)
    RelativeLayout bottomLayout;
    @Bind(R.id.puzzle_layout)
    FrameLayout puzzleLayout;
    @Bind(R.id.puzzle_bg_view)
    View puzzleBgView;
    // TODO: Rename and change types of parameters
    private int currentIndex;
    private int totalNum;

    private OnSeeWordPuzzleListener mListener;
    private List<String> standardAnswerList = new ArrayList<>();
    private List<String> writeAnswerList = new ArrayList<>();

    private List<String> imageUrlList = new ArrayList<>();
    private boolean isFirstChoose = false;
    private boolean finishedExchangeOnce = false;
    private Handler handler = new Handler();
    private String titleStr;
    private Dialog dialog;
    private JumpIntentKey.QUESTION_ENTER_TYPE type;
    private List<CartoonMediaBean> list = new ArrayList<>();
    private List<CartoonMediaBean> orginalList;
    private String homePackageId;
    private GridViewAdapter adapter;
    private List<CartoonCommitAnswerBean> commitAnswerBeanList;
    private int state; //判断对错
    private String studentHomeworkId;
    private String analysisText;
    private String lessonNameStr;
    private String unitNameStr;

    public SeeWordPuzzleNewFragment() {
        // Required empty public constructor
    }

    private JumpIntentKey.CARTOON_BUTTON_STATUS buttonStatus = JumpIntentKey.CARTOON_BUTTON_STATUS.STATUS_LIGHT;
    private QuestionVOsBean questionVOsBean;
    private Fragment currentFragment;


    @Override
    public String fmCallBackName() {
        return questionVOsBean.getConstructionNameCn();
    }

    /**
     *
     */
    // TODO: Rename and change types and number of parameters
    public static SeeWordPuzzleNewFragment newInstance(QuestionVOsBean list, int currentIndex, int totalNum, JumpIntentKey.QUESTION_ENTER_TYPE type,
                                                       String homePackageId, String studentHomeworkId, String lessonNameStr, String unitNameStr) {
        SeeWordPuzzleNewFragment fragment = new SeeWordPuzzleNewFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, currentIndex);
        args.putInt(ARG_PARAM2, totalNum);
        args.putSerializable(JumpIntentKey.QUESTION_ENTER, type);
        args.putParcelable(JumpIntentKey.QUSETION_BANK_LIST_KEY, list);
        args.putString(JumpIntentKey.HOMEWORK_PACKAGE_ID, homePackageId);
        args.putString(JumpIntentKey.STUDENTHOMEWORKID, studentHomeworkId);
        args.putString(JumpIntentKey.LESSON_NAME, lessonNameStr);
        args.putString(JumpIntentKey.UNIT_NAME, unitNameStr);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            currentFragment = this;
            currentIndex = getArguments().getInt(ARG_PARAM1);
            totalNum = getArguments().getInt(ARG_PARAM2);
            type = (JumpIntentKey.QUESTION_ENTER_TYPE) getArguments().getSerializable(JumpIntentKey.QUESTION_ENTER);
            homePackageId = getArguments().getString(JumpIntentKey.HOMEWORK_PACKAGE_ID);
            studentHomeworkId = getArguments().getString(JumpIntentKey.STUDENTHOMEWORKID);
            lessonNameStr = getArguments().getString(JumpIntentKey.LESSON_NAME);
            unitNameStr = getArguments().getString(JumpIntentKey.UNIT_NAME);
            questionVOsBean = getArguments().getParcelable(JumpIntentKey.QUSETION_BANK_LIST_KEY);


            if (NO_DO_SUBMMIT.equals(doQusValue)) {
                checkQuestionIsDone();
            } else {

            }
        }
    }


    private void showDialog() {

        if (dialog == null) {
            dialog = ProgressUtil.creatRequestDialog(getActivity(), "正在发送电波");
        }
        dialog.show();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_see_word_puzzle_new, container, false);
        ButterKnife.bind(this, view);
        showDialog();

        initClick();
        initData();
        initView();
        return view;
    }


    private void initGirdData() {
        LogUtil.MyLog("initGirdData", "===initGirdData==" + list.size());
        adapter = new GridViewAdapter(getActivity(), list);
        dragGridView.setAdapter(adapter);

        dragGridView.setMoveCallBack(new DragGridView.MoveCallBack() {
            @Override
            public void moveCallBack() {

                if (doQusValue.equals(NO_DO_SUBMMIT)) {
                    onButtonPressed(true, Integer.parseInt(NO_DO_SUBMMIT));

                    buttonStatus = JumpIntentKey.CARTOON_BUTTON_STATUS.STATUS_LIGHT;
                }

            }
        });
    }

    /**
     * 显示题目，选项
     */
    private void initData() {
        CartoonOptionsBean optionsBean = questionVOsBean.getOptions();
        CartoonAnswersBean answersBean = questionVOsBean.getAnswers();
        CartoonStemsBean stemsBean = questionVOsBean.getStems();
        List<CartoonTextsBean> textsList = stemsBean.getTexts();
        if (textsList != null && textsList.size() > 0) {
            String questionNameStr = textsList.get(0).getValue();
            if (!TextUtils.isEmpty(questionNameStr)) {
                questionName.setText(questionNameStr);
            }
        }


        CartoonAnswerKeysBean answerKeysBean = questionVOsBean.getAnswerKeys();
        if (answerKeysBean != null) {
            List<CartoonTextsBean> answerKeysList = answerKeysBean.getTexts();
            if (answerKeysList != null && answerKeysList.size() > 0) {

                analysisText = answerKeysList.get(0).getValue();
            }
        }

        titleStr = questionVOsBean.getConstructionNameCn();
        if (optionsBean != null) {

            list.removeAll(list);
            list.addAll(optionsBean.getImages());
            orginalList = new ArrayList<>();
            for (CartoonMediaBean bean : list) {
                CartoonMediaBean orginalBean = new CartoonMediaBean();
                orginalBean.setStatus(bean.getStatus());
                orginalBean.setId(bean.getId());
                orginalBean.setImgUrl(bean.getImgUrl());
                orginalBean.setPlayLink(bean.getPlayLink());
                orginalBean.setResourceName(bean.getResourceName());
                orginalBean.setType(bean.getType());
                orginalList.add(orginalBean);
            }
            initGirdData();
        }

        if (answersBean != null) {
            standardAnswerList.removeAll(standardAnswerList);
            for (int i = 0; i < answersBean.getTexts().size(); i++) {
                standardAnswerList.add(answersBean.getTexts().get(i).getValue());
            }
        }
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    private void initView() {

        switch (type) {
            case DO_WORK:
            case CONTINUE_WORK:
                previousQuestion.setVisibility(View.GONE);
                nextQuestion.setVisibility(View.GONE);
                break;
            case DO_IT_AGAIN:
                previousQuestion.setVisibility(View.GONE);
                nextQuestion.setVisibility(View.GONE);
                break;
            case WORK_REPORT:
                dragGridView.setEnabled(false);
                previousQuestion.setVisibility(View.VISIBLE);
                nextQuestion.setVisibility(View.VISIBLE);
                if (currentIndex == 0) {
                    previousQuestion.setVisibility(View.GONE);
                }
                if (currentIndex == totalNum - 1) {
                    nextQuestion.setVisibility(View.GONE);
                }
                getWorkReportAnswer();
                break;
            case HAS_CORRECTED:
            case NOT_CORRECTED:
            case ERROR_KINDS:
                previousQuestion.setVisibility(View.VISIBLE);
                nextQuestion.setVisibility(View.VISIBLE);
                if (currentIndex == 0) {
                    previousQuestion.setVisibility(View.GONE);
                }
                if (currentIndex == totalNum - 1) {
                    nextQuestion.setVisibility(View.GONE);
                }

                break;

            case TEACHER_WORK_PREVIEW:
                seeAnswer();
                break;
        }

        commitImage.setOnClickListener(this);
        previousQuestion.setOnClickListener(this);
        nextQuestion.setOnClickListener(this);

    }

    /**
     * 获取客观答案
     */
    private void getWorkReportAnswer() {

        Map<String, Object> map = new HashMap<>();
        map.put("packageId", homePackageId);
        map.put("classId", MyApplication.classIDStr);
        map.put("questionId", questionVOsBean.getQuestionId());

        HttpMehtod.getInstance().cartoonGetHomeAnswer(map, new CustomNetSubscriber(getActivity(), false) {
            @Override
            public void onNext(Response<ResponseBody> responseBodyResponse) {

                BaseBean<CartoonGetAnswerResultBean> baseBean = Utils.fromJsonObject(NetUtil.getResResult(responseBodyResponse), CartoonGetAnswerResultBean.class);
                CustomNetCallBack callBack = new CustomNetCallBack(getContext(), baseBean);
                callBack.setCallBack(new CustomNetCallBack.NetCallBack<CartoonGetAnswerResultBean>() {
                    @Override
                    public void success(CartoonGetAnswerResultBean dataBean) {

                        if (dataBean != null) {
                            CartoonGetHomeAnswerBean homeAnswerBean = dataBean.getResult();
                            List<CartoonCommitAnswerBean> answerResourceList = homeAnswerBean.getAnswerResourceList();
                            List<String> answerList = new ArrayList<>();
                            for (CartoonCommitAnswerBean bean : answerResourceList) {
                                answerList.add(bean.getQuestionResourceId());
                            }

                            List<CartoonMediaBean> tempList = new ArrayList<>();
                            for (String str : answerList) {
                                for (CartoonMediaBean bean : list) {
                                    if (str.contains(String.valueOf(bean.getId()))) {
                                        tempList.add(bean);
                                    }
                                }
                            }

//                            list.removeAll(list);
//                            list.addAll(tempList);
//                            LogUtil.MyLog("cartoonGetHomeAnswer", "=======" + list.size());
//                            adapter.notifyDataSetChanged();

                            puzzleBgView.setVisibility(View.VISIBLE);

                            if (Utils.compare(standardAnswerList, answerList)) {

                                puzzleBgView.setBackgroundResource(R.mipmap.cartoon_puzzle_right);
                                commitImage.setVisibility(View.INVISIBLE);

                                buttonStatus = JumpIntentKey.CARTOON_BUTTON_STATUS.STATUS_HIDE;

                            } else {
                                commitImage.setVisibility(View.VISIBLE);
                                buttonStatus = JumpIntentKey.CARTOON_BUTTON_STATUS.STATUS_SEE_ANSWER;
                                puzzleBgView.setBackgroundResource(R.mipmap.cartoon_puzzle_wrong);

                                Utils.notifyButtonBg(buttonStatus, commitImage);
                            }

                            if (type == JumpIntentKey.QUESTION_ENTER_TYPE.WORK_REPORT) {

                                if(isUserShow){
                                    if (getActivity() instanceof CartoonWorkQuestionTypeActivity) {
                                        Utils.notifyButtonBg(buttonStatus, ((CartoonWorkQuestionTypeActivity) getActivity()).getCommitImage());
                                    }
                                }

                            }

                        }

                    }

                    @Override
                    public void fail(String errorCode) {


                    }
                }).dealData();
            }
        });
    }


    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(boolean isDo) {
        if (mListener != null) {
            mListener.onSeeWordPuzzle(isDo, 0, "");
        }
    }

    public void onButtonPressed(boolean isDo, int num) {
        if (mListener != null) {
            mListener.onSeeWordPuzzle(isDo, num, "");
        }
    }

    private void initClick() {
//
//        Utils.notifyButtonBg(buttonStatus, commitImage);
//        commitImage.setOnClickListener(this);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnSeeWordPuzzleListener) {
            mListener = (OnSeeWordPuzzleListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnSeeWordPuzzleListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    /**
     * 判断题目是否正确
     */
    private void juegeRightOrWrong() {
        doQusValue = DO_SUBMMIT;


        writeAnswerList.removeAll(writeAnswerList);
//        writeAnswerList.clear();
        commitAnswerBeanList = new ArrayList<>();
        for (int i = 0; i < adapter.getStrList().size(); i++) {

            CartoonCommitAnswerBean bean = new CartoonCommitAnswerBean();
            bean.setQuestionResourceId(String.valueOf(adapter.getStrList().get(i).getId()));
            bean.setResourceValue("1"); //图片
            commitAnswerBeanList.add(bean);
            writeAnswerList.add(String.valueOf(adapter.getStrList().get(i).getId()));
        }
        if (Utils.compare(standardAnswerList, writeAnswerList)) {
            state = 1;
        } else {
            state = 0;
            if (type == JumpIntentKey.QUESTION_ENTER_TYPE.NOT_CORRECTED || type == JumpIntentKey.QUESTION_ENTER_TYPE.ERROR_KINDS) {
                doQusValue = NO_DO_SUBMMIT;
            }
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.commit_image:

                switch (buttonStatus) {
                    case STATUS_LIGHT:
                        juegeRightOrWrong();
                        switch (type) {
                            case DO_WORK:
                            case CONTINUE_WORK:
                            case DO_IT_AGAIN:
                            case HAS_CORRECTED:
                                commitAnswer();
                                break;
                            case NOT_CORRECTED:
                            case ERROR_KINDS:
                                if (state == 1) {
                                    errorQuestionCommitAnswer();
                                }
                                break;
                        }
                        break;
                    case STATUS_SEE_ANSWER:
                        seeAnswer();
                        break;
                    case STATUS_ANALYSIS:
                        CartoonAnalysisPopu popu = new CartoonAnalysisPopu(getActivity(), analysisText, commitImage);
                        popu.showPopupWindow();
                        break;
                }
                break;

            case R.id.previous_question:
                break;
            case R.id.next_question:
                break;
        }
    }

    /**
     * 查看答案
     */
    private void seeAnswer() {

        LogUtil.MyLog("seeAnswer", list.size() + "====seeAnswer====" + standardAnswerList.size());
        List<CartoonMediaBean> tempList = new ArrayList<>();
        for (String str : standardAnswerList) {
            for (CartoonMediaBean bean : list) {
                if (str.equals(String.valueOf(bean.getId()))) {
                    tempList.add(bean);
                }
            }
        }
        adapter.getStrList().removeAll(adapter.getStrList());
        list.removeAll(list);

        LogUtil.MyLog("seeAnswer", tempList.size() + "======tempList====" + list.size());

        list.addAll(tempList);

        puzzleBgView.setVisibility(View.VISIBLE);
        puzzleBgView.setBackgroundResource(R.mipmap.cartoon_puzzle_right);
        buttonStatus = STATUS_ANALYSIS;
        adapter.notifyDataSetChanged();

        if (getActivity() instanceof CartoonWorkQuestionTypeActivity) {
            Utils.notifyButtonBg(buttonStatus, ((CartoonWorkQuestionTypeActivity) getActivity()).getCommitImage());
        }

    }


    private void returnOrginalData() {
        if (orginalList != null && orginalList.size() > 0) {
            list.clear();
            list.addAll(orginalList);
        }
    }

    /**
     * 提交答案
     */
    private void commitAnswer() {

        juegeRightOrWrong();

        Map<String, Object> map = new HashMap<>();
        map.put("classId", MyApplication.classIDStr); // 测试

        map.put("state", state);
        map.put("homeworkPackageId", homePackageId);
        map.put("objectQuestionId", questionVOsBean.getQuestionId());
        map.put("answerResourceList", commitAnswerBeanList);
        map.put("studentHomeworkId", studentHomeworkId);
        HttpMehtod.getInstance().cartoonCommitHomeAnsers(map, new CustomNetSubscriber(getActivity()) {
            @Override
            public void onNext(Response<ResponseBody> responseBodyResponse) {

                switch (type) {

                    case HAS_CORRECTED:
                    case NOT_CORRECTED:
                    case ERROR_KINDS:

                        if (state == 1) {
                            CartoonToastUtils.show(true);
                        } else {
                            CartoonToastUtils.show(false);
                        }


                        if (state == 1) {
                            jumpToFragment();
                        } else {
                            puzzleBgView.setVisibility(View.VISIBLE);
                            buttonStatus = JumpIntentKey.CARTOON_BUTTON_STATUS.STATUS_SEE_ANSWER;
                            puzzleBgView.setBackgroundResource(R.mipmap.cartoon_puzzle_wrong);

                            if (getActivity() instanceof CartoonWorkQuestionTypeActivity) {
                                Utils.notifyButtonBg(buttonStatus, ((CartoonWorkQuestionTypeActivity) getActivity()).getCommitImage());
                            }

                        }
                        break;

                    case DO_WORK:
                    case DO_IT_AGAIN:
                    case CONTINUE_WORK:

                        if (state == 1) {
                            CartoonToastUtils.show(true);
                        } else {
                            CartoonToastUtils.show(false);
                        }

                        jumpToFragment();

                        break;
                }

            }
        });

    }


    /**
     * 错题中心 -- 未订正 错题分类
     */
    private void errorQuestionCommitAnswer() {
        Map<String, Object> map = new HashMap<>();
        map.put("studentHomeworkDoneDetailId", questionVOsBean.getStudentHomeworkDoneDetailId());
        HttpMehtod.getInstance().cartoonCorrectErrorQuestion(map, new CustomNetSubscriber(getActivity()) {
            @Override
            public void onNext(Response<ResponseBody> responseBodyResponse) {
                jumpToFragment();
            }
        });
    }

    @Override
    public void fmCallBack() {

        switch (buttonStatus) {

            case STATUS_LIGHT:

                switch (type) {
                    case DO_WORK:
                    case CONTINUE_WORK:
                    case DO_IT_AGAIN:
                    case HAS_CORRECTED:
                        commitAnswer();
                        break;
                    case NOT_CORRECTED:
                    case ERROR_KINDS:
                        juegeRightOrWrong();

                        if (state == 1) {
                            CartoonToastUtils.show(true);
                        } else {
                            CartoonToastUtils.show(false);
                        }


                        if (state == 1) {
                            errorQuestionCommitAnswer();
                        } else {
                            puzzleBgView.setVisibility(View.VISIBLE);
                            buttonStatus = JumpIntentKey.CARTOON_BUTTON_STATUS.STATUS_SEE_ANSWER;
                            puzzleBgView.setBackgroundResource(R.mipmap.cartoon_puzzle_wrong);

                            if (getActivity() instanceof CartoonWorkQuestionTypeActivity) {
                                Utils.notifyButtonBg(buttonStatus, ((CartoonWorkQuestionTypeActivity) getActivity()).getCommitImage());
                            }
                        }
                        break;
                }
                break;
            case STATUS_SEE_ANSWER:
                seeAnswer();
                break;
            case STATUS_ANALYSIS:
                CartoonAnalysisPopu popu = new CartoonAnalysisPopu(getActivity(), analysisText, commitImage);
                popu.showPopupWindow();
                break;

        }

    }

    @Override
    public String fmCallBackValue() {
        return doQusValue;
    }


    /**
     *
     */
    public interface OnSeeWordPuzzleListener {
        // TODO: Update argument type and name
        void onSeeWordPuzzle(boolean isDo, int totalNum, String title);
    }

    /**
     */
    private void checkQuestionIsDone() {
        if (type == JumpIntentKey.QUESTION_ENTER_TYPE.TEACHER_WORK_PREVIEW) {
            return;
        }
        if (type == JumpIntentKey.QUESTION_ENTER_TYPE.DO_IT_AGAIN) {
            return;
        }
        if (type == JumpIntentKey.QUESTION_ENTER_TYPE.NOT_CORRECTED) {
            return;
        }
        if (type == JumpIntentKey.QUESTION_ENTER_TYPE.HAS_CORRECTED) {
            return;
        }
        if (type == JumpIntentKey.QUESTION_ENTER_TYPE.ERROR_KINDS) {
            return;
        }
        if (type == JumpIntentKey.QUESTION_ENTER_TYPE.WORK_REPORT) {
            return;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("studentHomeworkId", studentHomeworkId);
        map.put("questionId", questionVOsBean.getQuestionId());
        HttpMehtod.getInstance().checkQuestionIsDone(map, new CustomNetSubscriber(getActivity()) {
            @Override
            public void onNext(Response<ResponseBody> responseBodyResponse) {

                BaseBean<CheckDoQuestion> baseBean = Utils.fromJsonObject(NetUtil.getResResult(responseBodyResponse), CheckDoQuestion.class);
                CustomNetCallBack callBack = new CustomNetCallBack(getContext(), baseBean);
                callBack.setCallBack(new CustomNetCallBack.NetCallBack<CheckDoQuestion>() {
                    @Override
                    public void success(CheckDoQuestion dataBean) {


                        if (dataBean.isIsDone()) {
                            doQusValue = NO_DO_SUBMMIT;
                        } else {
                            doQusValue = DO_SUBMMIT;
                        }

                        LogUtil.MyLog("checkQuestionIsDone", "==checkQuestionIsDone==" + dataBean.isIsDone());
                    }

                    @Override
                    public void fail(String errorCode) {

                    }
                }).dealData();
            }
        });
    }

    /**
     * 1 已提交
     * <p>
     * 0 未提交
     */
    public String doQusValue = NO_DO_SUBMMIT;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        LogUtil.MyLog("CartoonPicSpeakFragment", "=====setUserVisibleHint===" + isVisibleToUser);
        if (!isVisibleToUser) {

            if (type != JumpIntentKey.QUESTION_ENTER_TYPE.WORK_REPORT) {

                if (puzzleBgView != null) {
                    puzzleBgView.setVisibility(View.GONE);
                }

            }

            if (questionVOsBean != null) {
                if (NO_DO_SUBMMIT.equals(doQusValue)) {
                    checkQuestionIsDone();
                } else {

                }
            }
            isUserShow = false;
        } else {
            isUserShow = true;
            LogUtil.MyLog("adsfadfsasdfasdfasdf", "=====setUserVisibleHint===" + isVisibleToUser);
            if (type == JumpIntentKey.QUESTION_ENTER_TYPE.WORK_REPORT) {
                if (getActivity() instanceof CartoonWorkQuestionTypeActivity) {
                    Utils.notifyButtonBg(buttonStatus, ((CartoonWorkQuestionTypeActivity) getActivity()).getCommitImage());
                }
            }

        }

        super.setUserVisibleHint(isVisibleToUser);
    }

    boolean isUserShow = false;

    private void jumpToFragment() {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                onButtonPressed(true, Integer.parseInt(DO_SUBMMIT));
            }
        }, CartoonWorkQuestionTypeActivity.JUMP_FRG_TIME);
    }

}
